package com.atguigu.common.utils;

import lombok.SneakyThrows;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

class A{
private File file;
private Properties property=new Properties();

public A() throws IOException {
  init();
  Thread t=new Thread(new Listener());
  t.setDaemon(true);
  t.start();
}

private void init() throws IOException {
  property.load(new FileInputStream(file));//重新加载文件
}

class Listener implements Runnable{//扫描文件改动
  private long modifyTime=file.lastModified();
  @SneakyThrows
  public void run(){
    while(true){
      long l=file.lastModified();
      if(l>modifyTime){
        modifyTime=l;
        init();
      }
      Thread.sleep(100);
    }
  }

}}